trigger IYPProductDiscount on OpportunityLineItem (after insert,after update)
{
Set<Id> setoppid=new Set<Id>();
 ID RecTypeID = RecordTypeHelper.GetRecordTypeID('Opportunity','Contract');
for(OpportunityLineItem oli:trigger.new)
{
setoppid.add(oli.OpportunityId);
}
Map<Id,PricebookEntry> mapPricebookEntry=new Map<id,PricebookEntry>([Select ProductCode,Product2Id,Product2.Name,Name From PricebookEntry]);
List<Opportunity> lstopportunity=new List<Opportunity>();
for(Opportunity opp:[Select Approval_Discount__c,Approval_Product__c,Approval_Received__c,Amount,(Select OpportunityId,TotalPrice,PricebookEntryId, Approval_Discount__c From OpportunityLineItems) From Opportunity where Id in:setoppid and RecordTypeId=:RecTypeID])
{
    List<OpportunityLineItem> lstOpportunityLineItem=opp.OpportunityLineItems;
    Decimal Oppamount=0;
    for(OpportunityLineItem oli:lstOpportunityLineItem)
    {
    Oppamount+=oli.TotalPrice;
    }
   for(OpportunityLineItem oli:lstOpportunityLineItem)
    {
     
     string productname=mapPricebookEntry.get(oli.PricebookEntryId).Product2.Name;
     system.debug('testoli'+productname+'tst'+opp.Approval_Discount__c+' tst'+opp.Approval_Received__c+' tst'+opp.Amount);
      system.debug('testprod'+opp.Approval_Discount__c+'<'+oli.Approval_Discount__c);
     if(productname=='IYP' && opp.Approval_Discount__c==null && opp.Approval_Received__c == false && Oppamount>2500)
     {
        opp.Approval_Discount__c=oli.Approval_Discount__c;
        opp.Approval_Product__c='IYP';
        lstopportunity.add(opp);    
     }
     else if(productname=='IYP' && opp.Approval_Discount__c<oli.Approval_Discount__c && opp.Approval_Received__c == false && Oppamount>2500)
     {
        system.debug('testproduct'+opp.Approval_Discount__c+'<<<'+oli.Approval_Discount__c);
        opp.Approval_Discount__c=oli.Approval_Discount__c;
        opp.Approval_Product__c='IYP';
        lstopportunity.add(opp);        
     }
     else if(productname=='PRINT' && opp.Approval_Discount__c==null && opp.Approval_Received__c == false && Oppamount>2500)
     {
        opp.Approval_Discount__c=oli.Approval_Discount__c;
        opp.Approval_Product__c='PRINT';
        lstopportunity.add(opp);    
     }
     else if(productname=='PRINT' && opp.Approval_Discount__c<oli.Approval_Discount__c && opp.Approval_Received__c == false && Oppamount>2500)
     {
        opp.Approval_Discount__c=oli.Approval_Discount__c;
        opp.Approval_Product__c='PRINT';
        lstopportunity.add(opp);        
     }
     
    
    }
}
FollowUpOppHelper.sethaslineItem();
update lstopportunity;
system.debug('testoppty'+lstopportunity);
}